//
//  HOMessateListTableViewCell.m
//  神鸥翻译
//
//  Created by foguo-mac-1 on 3/7/16.
//  Copyright © 2016 ShenOu. All rights reserved.
//

#import "HOMessateListTableViewCell.h"
#import "HOImageMgr.h"
#import "HOUtils.h"

@interface HOMessateListTableViewCell()
{
	UIImageView		*headerImgView;
	UILabel			*titleLbl;
	UILabel			*contentLbl;
	UILabel			*timerLbl;
	UIImageView		*goImgView;
}
@end

@implementation HOMessateListTableViewCell

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

- (void)initWithWidth:(CGFloat)width
{
	self.cellWidth = width;
	[self initHeaderImgView];
	[self initTitleLbl];
	[self initContentLbl];
	[self initTimeLabel];
//	[self initGoImgView];
}

- (void)initHeaderImgView
{
	headerImgView = [[UIImageView alloc]
					 initWithFrame:CGRectMake(HO_HORIZONAL_PADDING,
											  18,
											  30,
											  30)];
	headerImgView.image = [UIImage imageNamed:@"icon_system_remind"];
	[self.contentView addSubview:headerImgView];
}

- (void)initTitleLbl
{
	CGFloat x = headerImgView.frame.size.width + headerImgView.frame.origin.x + 2 * HO_HORIZONAL_PADDING - 5;
	titleLbl = [[UILabel alloc]
					 initWithFrame:CGRectMake(x,
											  HO_HORIZONAL_PADDING,
											  self.cellWidth - x - 130,
											  22)];
	titleLbl.textColor = TEXT_GRAY_DARK_COLOR;
//	titleLbl.layer.borderWidth = 1;
	titleLbl.font = [UIFont systemFontOfSize:14];
	[self.contentView addSubview:titleLbl];
}

- (void)initContentLbl
{
//	CGFloat x = headerImgView.frame.size.width + headerImgView.frame.origin.x + 2 * HO_HORIZONAL_PADDING - 5;
	contentLbl = [[UILabel alloc]
				  initWithFrame:CGRectMake(titleLbl.frame.origin.x,
											titleLbl.frame.origin.y + titleLbl.frame.size.height + 5,
										 self.cellWidth - headerImgView.frame.size.width - headerImgView.frame.origin.x - 4 * HO_HORIZONAL_PADDING - 30,
										 50)];
	contentLbl.textColor = TEXT_GRAY_COLOR;
//	contentLbl.layer.borderWidth = 1;
	contentLbl.numberOfLines = 2;
	contentLbl.font = [UIFont systemFontOfSize:13];
	[self.contentView addSubview:contentLbl];
}

- (void)initTimeLabel
{
	timerLbl = [[UILabel alloc]
				initWithFrame:CGRectMake(self.cellWidth - 130,
										 HO_HORIZONAL_PADDING,
										 100,
										 22)];
	timerLbl.textColor = TEXT_GRAY_COLOR;
//	timerLbl.layer.borderWidth = 1;
	timerLbl.textAlignment = NSTextAlignmentRight;
	timerLbl.font = [UIFont systemFontOfSize:12];
	[self.contentView addSubview:timerLbl];
}

- (void)initGoImgView
{
	goImgView = [[UIImageView alloc] init];
	goImgView.frame = CGRectMake(self.cellWidth - [[HOImageMgr sharedInstance] getGoImage].size.width - HO_HORIZONAL_PADDING,
								 (64 - goImgView.frame.size.height) / 2,
								 [[HOImageMgr sharedInstance] getGoImage].size.width,
								 [[HOImageMgr sharedInstance] getGoImage].size.height);
//	goImgView.layer.borderWidth = 1;
	goImgView.image = [[HOImageMgr sharedInstance] getGoImage];
	[self.contentView addSubview:goImgView];
}

- (void)setMessage:(HOMessageEntity *)message
{
	titleLbl.text = message.title;
	contentLbl.text = message.message;
//	contentLbl.layer.borderWidth = 1;
	[contentLbl sizeToFit];
	contentLbl.frame = CGRectMake(contentLbl.frame.origin.x,
								  contentLbl.frame.origin.y,
								   self.cellWidth - headerImgView.frame.size.width - headerImgView.frame.origin.x - 4 * HO_HORIZONAL_PADDING - 30,
								  contentLbl.frame.size.height);
	timerLbl.text = [HOUtils getDateFromTimeInterval3:message.createTime];
	
	CGFloat y = contentLbl.frame.size.height + contentLbl.frame.origin.y + HO_HORIZONAL_PADDING;
	self.cellHeight = MAX(y, 64);
	goImgView.frame = CGRectMake(self.cellWidth - [[HOImageMgr sharedInstance] getGoImage].size.width - HO_HORIZONAL_PADDING,
								 (self.cellHeight - goImgView.frame.size.height) / 2,
								 goImgView.frame.size.width,
								 goImgView.frame.size.height);
	
	
	headerImgView.image = [UIImage imageNamed:@"icon_system_remind"];
}

- (CGFloat)getCellHeight
{
	return contentLbl.frame.size.height + contentLbl.frame.origin.y + 10;
}

- (void)dealloc
{
	[HOUtils removeFromSuperViewForViews:headerImgView,
										titleLbl,
										contentLbl,
										timerLbl,
										goImgView];
	[headerImgView release];
	[titleLbl release];
	[contentLbl release];
	[timerLbl release];
	[goImgView release];
	[super dealloc];
}

@end
